// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './components/store'
import VueCordova from 'vue-cordova'
import Http from './components/http'
import TcFlex from '@/controls/TcFlex.vue'
import TcView from '@/controls/TcView.vue'

Vue.use(VueCordova)
Vue.component('tc-flex', TcFlex)
Vue.component('tc-view', TcView)

Vue.config.productionTip = false

if (window.cordova) {
  document.addEventListener('deviceready', function () {
    console.log('deviceready')
    // navigator.splashscreen.hide()
    // StatusBar.backgroundColorByHexString('#2FA4E9')
    StatusBar.overlaysWebView(false)
    const init = new Vue({
      el: '#app',
      store,
      router,
      components: { App },
      template: '<App/>'
    })
    // 检查版本更新
    Http.get(Http.Urls.getWebVersion).then(
      res => {
        console.log(res)
        chcp.getVersionInfo((err, data) => {
          console.log(err)
          if (data.currentWebVersion === res['release']) {
            navigator.splashscreen.hide()
          } else {
            chcp.fetchUpdate(function (error, data) {
              navigator.splashscreen.hide()
              if (!error) {
                chcp.installUpdate(function (error) {
                  console.log(error)
                })
              }
            })
          }
        })
      }
    )
  }, false)
} else {
  const init = new Vue({
    el: '#app',
    store,
    router,
    components: { App },
    template: '<App/>'
  })
}
